const {ccclass, property} = cc._decorator;
import Actor from './actor/Actor'

@ccclass
export default class Poker extends cc.Component {
    
    @property(cc.Sprite)
    up: cc.Sprite = null;

    @property(cc.Sprite)
    down: cc.Sprite = null;

    @property(cc.Sprite)
    m_type: cc.Sprite = null;

    @property({type:[cc.SpriteFrame]})
    typeList:cc.SpriteFrame[]=[];

    @property({type:[cc.SpriteFrame]})
    blackNumberList:cc.SpriteFrame[]=[];

    @property({type:[cc.SpriteFrame]})
    redNumberList:cc.SpriteFrame[]=[];

    private updatePokeFrame(frame:cc.SpriteFrame){
        this.up.spriteFrame = frame;
        this.down.spriteFrame = frame;
    }
    //牌的顺序大小
    sortSize:number = 0;
    _typeIndex:number;
    _nameIndex:number;
    protected isJoker():boolean{
        return this._typeIndex == 4 || this._typeIndex == 5;
    }

    protected setSortSize(ptype,pname){
        this._typeIndex = ptype;
        this._nameIndex = pname;
        this.sortSize = pname;
    }

   
    /**
     * 
     * @param type  3 黑桃  2 红桃  1 梅花 0 方块  9 小王  10 大王
     * @param name  A - K = 012  14 小王  15 大王
     */
    setPocker(type:number,name:number){

        //红色
        if(type==0||type==2){
            this.updatePokeFrame(this.redNumberList[name])
            this.m_type.spriteFrame = this.typeList[type];
            
        }
        //黑色字
        else if(type==1||type==3){
            this.updatePokeFrame(this.blackNumberList[name])
            this.m_type.spriteFrame = this.typeList[type];
        }
        //大小王
        if(type==4||type==5){
            this.updatePokeFrame(this.typeList[type])
            this.m_type.spriteFrame = null;
        }
       
        this.setSortSize(type,name);
        
        cc.log(type,name,this.sortSize)
       
    }

    //是不是在下面
    isDown = true;
    UP_DOWN_STEP = 20;
    selected = false;
    actor:Actor;
    currentDown(){
        this.isDown = true;
        this.node.parent.setPositionY(0);
    }
    currentUp(){
        this.isDown = false;
        this.node.parent.setPositionY(this.UP_DOWN_STEP);
    }
            
    mouseDown(){
        this.actor.openSelect = true;
        this.mouseEnter();
    }
    changeUpOrDown(){
        this.isDown?this.currentUp():this.currentDown();
    }
    mouseEnter(){
        if(this.actor&&this.actor.openSelect){
            this.selected = true;
            this.actor.node.emit("pokerSelect",this)
        }
    }
    start(){
        this.node.on(cc.Node.EventType.MOUSE_ENTER,this.mouseEnter,this);
        this.node.on(cc.Node.EventType.MOUSE_DOWN,this.mouseDown,this);
        this.node.on(cc.Node.EventType.MOUSE_UP,this.actor.mouseUp,this.actor);

        
    }

  
    onLoad() {

        
        
    }
}
